<?php
namespace app\index\controller;
use think\Controller;
use think\Request;
use auth\Auth;
use think\Session;
class Common extends Controller
{
  public function _initialize()
  {
    if (Session::get('user.uid')) {
      $request = Request::instance();
      //$node=$request->module() . '/' . $request->controller() . '/' . $request->action();
      $node='/' . $request->controller() . '/' . $request->action();
      $AUTH = new \auth\Auth();//加载外部类
      if(!$AUTH->check($node,Session::get('user.uid')) && $node!='/Common/check_node'){
        $this->result('','1002','没有权限'.$node);
        exit();
      }
    }else{
      $this->result('','1001','请重新登录');
    }
  }
  public function check_node()
  {
    $AUTH = new \auth\Auth();//加载外部类
      if (Session::get('user.uid')) {
        if (Session::get('jurisdiction.role')=='超级管理员') {
          $node = Request::instance()->get('url');
          if ($node=='undefined') {
            $node='/';
          }
          $node_arr=explode('?', $node);
          if (!empty($node_arr)) {
            $node=$node_arr['0'];
            
          }
          if(!$AUTH->check($node,Session::get('user.uid'))){
            $this->result('','1002','没有权限'.$node);
          }else{
            $this->result('','0','用户正常');
          }
        }else{
          $this->result('','0','用户正常');
        }
      }else{
        $this->result('','1001','请登录');
      }
  }


}
